home *** CD-ROM | disk | FTP | other *** search
/ MacHome 1999 Game / Image.bin / Role Playing and Strategy / Starbound II.hqx / Starbound II / AI agents / Gypsum.rsrc / ss$t_148 < prev   
Encoding:
Text File  |  1998-05-14  |  3.8 KB  |  135 lines

  1. situation planet_production
  2. vars
  3.    p : planet;
  4.    i : integer;
  5.    st : integer;
  6.    success : boolean;
  7.    hex : integer;
  8.    struct : structure;
  9.  
  10. function Find_empty_hex(p : planet) : integer;
  11. vars
  12.    target : integer;
  13.    
  14. begin
  15.    target := Random(127);
  16.    while (Hex_structure(p, target) <> nil) do
  17.       target := Random(127);
  18.    return(target);
  19. end;
  20.  
  21.  
  22. // Main function
  23. begin
  24.    p := This_planet();
  25.    // First set the tech spending levels
  26.    Set_weapon_spending(p, w_spending);
  27.    Set_shield_spending(p, s_spending);
  28.    Set_move_spending(p, m_spending);
  29.    Set_detect_spending(p, d_spending);
  30.    Set_develop_spending(p, 50);
  31.    // Now see if we want to build a ship
  32.    if ((Planet_weapon(p) > tech_min) and
  33.        (Planet_shield(p) > tech_min) and
  34.        (Planet_move(p) > tech_min) and
  35.        (Planet_detect(p) > tech_min)) then
  36.       Set_ship_spending(p, 100);
  37.    else
  38.       Set_ship_spending(p, 0);
  39.    
  40.    // If there are more then two ships, then send out a squad
  41.    if (Orbit_num_ships(p) >= 3) then
  42.       begin
  43.          i := 1;     // Don't want to send starbase
  44.          while (i < Orbit_num_ships(p)) do
  45.             begin
  46.                success := Orbit_depart(p, i, true);
  47.                i := i + 1;
  48.             end;
  49.       end;
  50.  
  51.    // If a new ship has been built then set the ship type
  52.    if (New_ship(p)) then
  53.       begin
  54.          i := 0;
  55.          while (Can_build_ship_type(p, i)) do
  56.             i := i + 1;
  57.          if (i > 0) then
  58.             begin
  59.                st := Random(i);
  60.                success := Construct_ship_type(p, st);
  61.             end;
  62.          
  63.          // Now set the troops to fill it
  64.          i := 0;
  65.          while (i < 8) do
  66.             begin
  67.                success := Stardock_set_manifest(p, i, 0);
  68.                i := i + 1;
  69.             end;
  70.          // Now refill the barracks
  71.          success := true;
  72.          while (success) do
  73.             begin
  74.                i := Random(7) + 1;
  75.                while (not Can_build_troop(p, i)) do
  76.                   i := Random(7) + 1;
  77.                success := Stardock_set_manifest(p, i, Stardock_get_manifest(p, i)+1);
  78.             end;
  79.        end;
  80.    
  81.    // If there are 0 projects, then build a barracks or space port.
  82.    if (Num_projects(p) = 0) then
  83.       begin
  84.          if (Num_structures(p, 10) < 6) then       // space port
  85.             begin
  86.                // Select a random hex
  87.                hex := Find_empty_hex(p);
  88.                success := Create_structure(p, hex, 10);
  89.             end;
  90.          if (Num_structures(p, 2) < 6) then        // barracks
  91.             begin
  92.                // Select a random hex
  93.                hex := Find_empty_hex(p);
  94.                success := Create_structure(p, hex, 2);
  95.             end;
  96.       end;
  97.       
  98.    // See if we need to reorganize the barracks
  99.    if (New_troop(p)) then
  100.       begin
  101.          struct := First_structure(p);
  102.          while (struct <> nil) do
  103.             begin
  104.                if ((Structure_type(p, struct) = 2) and
  105.                    (Structure_left(p, struct) = 0)) then
  106.                   begin
  107.                      // Clear the old troops in the barracks
  108.                      i := 1;
  109.                      while (i < 8) do
  110.                         begin
  111.                            success := Set_barracks(p, struct, i, 0);
  112.                            i := i + 1;
  113.                         end;
  114.                      // Now refill the barracks, try one of each
  115.                      i := 7;
  116.                      while (i > 1) do
  117.                         begin
  118.                            if (Can_build_troop(p, i)) then
  119.                               success := Set_barracks(p, struct, i, Get_barracks(p, struct, i)+1);
  120.                            i := i - 1;
  121.                         end;
  122.                   end;
  123.                struct := Next_structure(p, struct);
  124.             end;
  125.       end;
  126. end;
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.